package com.dp.system.service.impl;

import java.util.List;
import com.dp.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dp.system.mapper.SysAlarmRuleMapper;
import com.dp.system.domain.SysAlarmRule;
import com.dp.system.service.ISysAlarmRuleService;

/**
 * 报警规则Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-10
 */
@Service
public class SysAlarmRuleServiceImpl implements ISysAlarmRuleService {

    @Autowired
    private SysAlarmRuleMapper sysAlarmRuleMapper;

    /**
     * 查询报警规则
     */
    @Override
    public SysAlarmRule selectSysAlarmRuleByRuleId(Long ruleId) {
        return sysAlarmRuleMapper.selectSysAlarmRuleByRuleId(ruleId);
    }

    /**
     * 查询报警规则列表
     */
    @Override
    public List<SysAlarmRule> selectSysAlarmRuleList(SysAlarmRule sysAlarmRule) {
        return sysAlarmRuleMapper.selectSysAlarmRuleList(sysAlarmRule);
    }

    /**
     * 新增报警规则
     */
    @Override
    public int insertSysAlarmRule(SysAlarmRule sysAlarmRule) {
        sysAlarmRule.setCreateTime(DateUtils.getNowDate());
        return sysAlarmRuleMapper.insertSysAlarmRule(sysAlarmRule);
    }

    /**
     * 修改报警规则
     */
    @Override
    public int updateSysAlarmRule(SysAlarmRule sysAlarmRule) {
        sysAlarmRule.setUpdateTime(DateUtils.getNowDate());
        return sysAlarmRuleMapper.updateSysAlarmRule(sysAlarmRule);
    }

    /**
     * 批量删除报警规则（修正参数类型）
     * 注意：参数是数组 Long[]，而非 List
     */
    @Override
    public int deleteSysAlarmRuleByRuleIds(Long[] ruleIds) {
        return sysAlarmRuleMapper.deleteSysAlarmRuleByRuleIds(ruleIds);
    }

    /**
     * 删除报警规则信息（单条）
     */
    @Override
    public int deleteSysAlarmRuleByRuleId(Long ruleId) {
        return sysAlarmRuleMapper.deleteSysAlarmRuleByRuleId(ruleId);
    }

    @Override
    public SysAlarmRule selectSysAlarmRuleByGreenhouseId(Long greenhouseId) {
        SysAlarmRule query = new SysAlarmRule();
        query.setGreenhouseId(greenhouseId);
        List<SysAlarmRule> rules = sysAlarmRuleMapper.selectSysAlarmRuleList(query);
        return rules.isEmpty() ? null : rules.get(0);
    }

}